<?php
require_once dirname(__FILE__) . '/../includes/common.inc.php';
require_once dirname(__FILE__) . '/../includes/pdoorm.inc.php';

header('Content-Type: text/plain');

$q = json_decode(MiscUtils::getParam('q', NULL));
//print_r($q);
//print_r($q->a);
//die;*/


	if(isset($q->a->e_oid) || isset($q->a->id) )
	{
	    switch($q->n){
	        case'parcels':
	            pdofind1($action,$condition,$e_oid);
	            break;  
	            
	        default:
	             pdofind($action,$condition,$e_oid);
	            break;  
	        
	    }  	
		
	}else{
	    switch($q->n){
	        case'parcels':
	            pdoparcelsadd($q->n,$q->a);
	            break;  
	            
	        default:
	             pdoparcelsadd($q->n,$q->a);
	            break;  
	        
	    }  		
		
	}




 
 /**
  * 
  * pdoadd
  */
 function pdoparcelsadd($tablename,$obj,$debug='')
 {
    if(!empty($debug))
    {
        echo"\n";
        echo"*********************以下为增加操作!**tablename:".$tablename."***************************";
        echo"\n";
        print_r($obj);
        //die;
    }
    
    if(!empty($obj))
    {
            $producefield = '';
            $producevalue = '';
            
            foreach($obj as $key=>$value)
            {
    
                    if(!in_array($key,array('pi_selects','v2_pUsers','v2_purchaseItems','v2_events','v2_tracks','v2_produces','v2_notes','_exist')))
                    {
                        $producefield .='`'.$key.'`,';
    
                        if(in_array($key,array('deadline','createdDate','sentDate','receivedDate','date','when','isExpired')))
                        {
                            if(is_object($obj->$key))
                            {
                                $value = SimpleDate::toStamp($value);
                                if(empty($value)) $value = 0;
                            }else{
                                if(empty($obj->$key)) $value = 0;
                            }
                            
                        }
                            
                        $producevalue .= " '".addslashes($value)."',";                      
                    
                    }
                
            }

            $producefield = substr($producefield,0,-1);
            $producevalue = substr($producevalue,0,-1);

            $producesql = "insert into ns_".$tablename."(`e_oid`,".$producefield.") values(NULL,".$producevalue.")";  
             
            if(!empty($debug))
            {
                echo $producesql."\n";         
            }else{
                sql_execute($producesql);
            } 
            
            unset($key);
            unset($value);
        
    }//obj not null
    
    
    
 }
 

 
 
 
   

?>